//
//  PlistViewController.m
//  GCD
//
//  Created by fangyuan ding on 2020/8/12.
//  Copyright © 2020 fangyuan ding. All rights reserved.
//

#import "PlistViewController.h"

@interface PlistViewController ()

@end

@implementation PlistViewController

- (void)viewDidLoad {
    [super viewDidLoad];
     //1.创建plist在沙盒中
    NSFileManager *fm = [NSFileManager defaultManager];
    //找到Documents文件所在的路径
    NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    //取得第一个Documents文件夹的路径
    NSString *filePath = [path objectAtIndex:0];
    NSString *plistPath = [filePath stringByAppendingPathComponent:@"test.plist"];
    [fm createFileAtPath:plistPath contents:nil attributes:nil];
    NSDictionary *dic = @{@"张三":@"1",@"李四":@"2"};
    [dic writeToFile:plistPath atomically:YES];
    NSLog(@"filePath = %@",filePath);
//    //删除文件
//    [fm removeItemAtPath:filePath error:nil];
    
    
    //2.获取plist文件路径下的值
    NSString *getPath = [[NSBundle mainBundle]pathForResource:@"test" ofType:@"plist"];
    NSDictionary *getDict = [NSDictionary dictionaryWithContentsOfFile:getPath];
    
    NSLog(@"%@",getDict);
   
}



@end
